//
//  BaseTabbarVC.m
//  HousingPoliceAssistant
//
//  Created by 云警01 on 2019/6/6.
//  Copyright © 2019 盛洋. All rights reserved.
//255 210 228  粉色 FFD2E4     29@3x  60@1x
//237 141 134  标签字体 ED8D86

#import "BaseTabbarVC.h"
#import "BaseNavVC.h"
#import "BaseTabBar.h"

#import "HomeVC.h"

@interface BaseTabbarVC ()<BaseTabBarDelegate>
{
    HomeVC *homeVC;
}

/*
 * 控制器数组
 */
@property (nonatomic, strong) NSMutableArray *ControllerMutableArry;

@end

@implementation BaseTabbarVC


#pragma mark -- 第一次使用当前类的时候对设置UITabBarItem的主题
+ (void)initialize
{
    UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];

    NSMutableDictionary *dictNormal = [NSMutableDictionary dictionary];
    dictNormal[NSForegroundColorAttributeName] = [UIColor grayColor];
    dictNormal[NSFontAttributeName] = [UIFont systemFontOfSize:11];

    NSMutableDictionary *dictSelected = [NSMutableDictionary dictionary];
    dictSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    dictSelected[NSFontAttributeName] = [UIFont systemFontOfSize:11];

    [tabBarItem setTitleTextAttributes:dictNormal forState:UIControlStateNormal];
    [tabBarItem setTitleTextAttributes:dictSelected forState:UIControlStateSelected];

}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //添加子控制器
    [self addChildVC];
    
    //是否添加凸起按钮
//    [self addTubar];
    
}

-(void)addTubar{
    
    //创建自己的tabbar，然后用kvc将自己的tabbar和系统的tabBar替换下
    BaseTabBar *tabbar = [[BaseTabBar alloc] init];
    tabbar.myDelegate = self;
    //kvc实质是修改了系统的_tabBar
    [self setValue:tabbar forKeyPath:@"tabBar"];
}

#pragma mark - 初始化tabBar上除了中间按钮之外所有的按钮
-(void)addChildVC{
    
//    _ControllerMutableArry = [[NSMutableArray alloc]init];
//    self.viewControllers = _ControllerMutableArry;
    
    homeVC = [[HomeVC alloc]initWithNibName:@"HomeVC" bundle:nil];
    [self addChildVc:homeVC imageName:@"test" selectImage:@"test-2" title:@"麻麻躲猫猫"];
    
}

//添加子控制器的方法
-(void)addChildVc:(UIViewController *)childVc imageName:(NSString *)imageName selectImage:(NSString *)selectImageName title:(NSString *)title{
    //设置跟控制器
    BaseNavVC * nav = [[BaseNavVC alloc]initWithRootViewController:childVc];
    
    childVc.title = title;
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"FFC3E4"]} forState:UIControlStateSelected];
    
    //正常状态下的图片
    childVc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    //不让图片渲染成蓝色
    UIImage * selectImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //选中状态下的图片
    childVc.tabBarItem.selectedImage = selectImage;
    
    [self addChildViewController:nav];

}

//当点击某个标签时
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    if ([item.title isEqualToString:@"首页"]) {
    }
}

#pragma mark -- LBTabBarDelegate

//点击中间按钮的代理方法
- (void)tabBarPlusBtnClick:(BaseTabBar *)tabBar
{
//    NSMutableString *str = [[NSMutableString alloc]initWithFormat:@"tel:%@",@"13035277730"];
//    UIWebView *callWebview = [[UIWebView alloc]init];
//    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//    [self.view addSubview:callWebview];
//    WebVC *vc = [[WebVC alloc]init];
//    BaseNavVC *vc1 = [[BaseNavVC alloc]initWithRootViewController:vc];
//    [self presentViewController:vc1 animated:YES completion:nil];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
